<template>
  <!--右键菜单-->
  <div v-show="options.showRightClickMenu" :style="{top:options.location.y + 'px',left:options.location.x + 'px'}" class="menuBox">
    <div v-for="item in options.menulists" @click="emit(item.fnHandler)" class="li flex flex-row a-item">
      <i :class="item.icoName"></i>
      <div >{{ item.btnName }}</div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'rightClickMenu',
  props:{
    options:{
      type: Object,
      default: {}
    }
  },
  watch:{
    'options.showRightClickMenu'(n){
      n &&  window.addEventListener('click',this.closeMenu)
    }
  },
  methods:{
    closeMenu(e){
      const menuBox = document.querySelector('.menuBox')
      const index = e.path.findIndex(item=>item === menuBox)
      if (!~index){
        this.options.showRightClickMenu = false
        window.removeEventListener('click',this.closeMenu)
      }
    },
    emit(fnHandler){
      this.$emit(fnHandler,true)
      this.options.showRightClickMenu = false
      window.removeEventListener('click',this.closeMenu)
    }
  }
}
</script>

<style lang="scss" scoped>
.menuBox{
  position: fixed;
  z-index: 9999;
  border: 1px solid rgba(203,203,203,0.8);
  background-color: #ffffff;
  font-size: 18px;
  .li{
    height: 30px;
    cursor: pointer;
    padding-right: 15px;
    min-width: 100px;
    i{
      width: 30px;
    }
     &:hover{
       background-color: rgba(203,203,203,.5);
     }
  }
}
</style>
